package custom.security.web.config;

import custom.security.web.filter.TimeFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;
import java.util.ArrayList;
import java.util.List;

/**
 * 通过configruration配置外部没有注入到spring上下文当中的类
 * Created by security on 2017/9/24.
 */
@Configuration
public class FilterConfig {

    /**
     * 一个bean相当于spring.xml中的bean配置
     * @return
     */
    @Bean
    public FilterRegistrationBean timeFilter(){
        FilterRegistrationBean fr = new FilterRegistrationBean();
        Filter timeFilter = new TimeFilter();
        fr.setFilter(timeFilter);
        List<String> filterUrls = new ArrayList<>();
        filterUrls.add("/user/*");
        fr.setUrlPatterns(filterUrls);
        return fr;
    }
}
